﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using StudyCode.ORM.Entities;
using StudyCode.ORM.Repository;

namespace StudyCode.ORM
{
    public partial class MainForm : Form, ICloneable
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            //txtSql.Text=SqlBuilder.InsertBuild(new User()
            //{
            //    Id = 1,
            //    Name = "Skyven",
            //    Address = "Mars",
            //    Age = 25,
            //    Gender = false,
            //});

            txtSql.Text = SqlBuilder.InsertBuild(new Book()
            {
                Id = 1,
                AuthorId = 1,
                BugTime = DateTime.Now,
                Count = 1,
                Name = "Michael",
                Number = "M00001",
                Price = 90,
            });
        }

        private void btnExcuteAdd_Click(object sender, EventArgs e)
        {
            IRepository<User> userRepository = new Repository<User>();

            userRepository.Insert(new User()
            {
                Id = 1,
                Name = "Skyven",
                Address = "Mars",
                Age = 25,
                Gender = false,
            });

            IRepository<Book> bookRepository = new Repository<Book>();

            bookRepository.Insert(new Book()
            {
                Id = 1,
                Name = "Skyven"
            });
        }

        private void btnUpdateBuild_Click(object sender, EventArgs e)
        {
            txtSql.Text = SqlBuilder.UpdateBuild(new User()
            {
                Id = 1,
                Name = "Skyven",
                Address = "Mars",
                Age = 25,
                Gender = false,
            });
        }

        private void btnUpdateExcute_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            txtSql.Text = SqlBuilder.DeleteBuild(new User()
            {
                Id = 1,
                Name = "Skyven",
                Address = "Mars",
                Age = 25,
                Gender = false,
            });
        }

        private void btnGetBuild_Click(object sender, EventArgs e)
        {
            txtSql.Text = SqlBuilder.Get<User>(1);
        }

        private void btnGetExcute_Click(object sender, EventArgs e)
        {
            IRepository<User> userRepository = new Repository<User>();
            var user = userRepository.Get(1);
            txtSql.Text = Entity.Serizalite(user);
        }

        private void btnDeleteExcute_Click(object sender, EventArgs e)
        {

        }

        public object Clone()
        {
            throw new NotImplementedException();
        }

        private void btnComplexQuery_Click(object sender, EventArgs e)
        {
           txtSql.Text= SqlBuilder.GetComplex(typeof (Book), 1);
        }
    }


}
